<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>升级自定义元素</title>
</head>
<body>
  <script>
    // 在自定义元素有定义之前会创建 HTMLUnknownElement 对象
    const fooElement = document.createElement('x-foo');

    // 创建自定义元素
    class FooElement extends HTMLElement {}
    customElements.define('x-foo', FooElement);

    console.log(fooElement instanceof FooElement);  // false

    // 强制升级
    customElements.upgrade(fooElement);

    console.log(fooElement instanceof FooElement);  // true
  </script>
</body>
</html>